#include "Window.h"

Window::Window(int width, int height, std::string title)
:   _size(width, height),
    _title(title),
    _settings(24, 8, 2),
    _window(sf::VideoMode((unsigned int)width, (unsigned int)height, 32), title, sf::Style::Close, _settings),
    _open(true)
{
    //glViewport(0, 0, width, height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glOrtho(0.0f, width , height, 0.0f, -1.0f, 1.0f);
    //gluPerspective(45.0f, (double) width / (double) height , 0.f, 100.f);

    glClearColor(0.f, 0.f, 1.f, 0.f); //blue
}

Window::~Window()
{
    //dtor
}

/// clears the window
void Window::clear()
{
    glClear(GL_COLOR_BUFFER_BIT);
}

/// displays the window
void Window::display()
{
    _window.display();
}

/// takes the event in the param and updates it with the window
bool Window::getEvent(sf::Event& event)
{
    return _window.pollEvent(event);
}

/// closes the window
void Window::close()
{
    _open = false;
    _window.close();
}

/// tells if the window is open  or not
bool Window::open()
{
    return _open;
}

/// takes a key enum value and returns true if the key was pressed
bool Window::keyPressed(sf::Keyboard::Key key)
{
    return sf::Keyboard::isKeyPressed(key);
}

/// returns if the mouse button is clicked
bool Window::mouseClicked(sf::Mouse::Button button)
{
    return sf::Mouse::isButtonPressed(button);
}

/// returns the mouse coords
sf::Vector2i Window::mouseCoords()
{
    return sf::Mouse::getPosition(_window);
}

/// returns the size of the window
sf::Vector2i Window::size()
{
    return _size;
}
